package database

import (
	"blog2/util"
	"time"
)

type Comment struct {
	CommentId   int       `gorm:"column:comment_id;primaryKey"`
	BlogId      int       `gorm:"column:blog_id"`
	CommentText string    `gorm:"column:comment_text"`
	CommentUid  int       `gorm:"column:comment_uid"`
	UpdateTime  time.Time `gorm:"column:comment_date"`
}

func (Comment) TableName() string {
	return "blog_comments"
}

var (
	_all_blog_comments_fields = util.GormFields(Comment{})
)

func CreateComment(blogId, commentUid int, commentText string) error {
	db := GetBlogDBConnection()
	if err := db.Create(&Comment{
		BlogId:      blogId,
		CommentUid:  commentUid,
		CommentText: commentText,
		UpdateTime:  time.Now()}).Error; err != nil {
		util.LogRus.Errorf("Error creating comment, blogId: %d, commentUid: %d, commentText: %s",
			blogId, commentUid, commentText)
		return err
	}
	util.LogRus.Infof("Created comment successfully, blogId: %d, commentUid: %d :", blogId, commentUid)
	return nil
}

func GetCommentsByBlogId(blogId int) ([]*Comment, error) {
	comments := make([]*Comment, 0)
	return comments, nil
}

func DeleteCommentByCommentId(commentId int) *Comment {
	return nil
}
